using System;
using System.Data;
using System.Data.OleDb;
using PCSComUtils.Common;
using PCSComUtils.DataAccess;

using PCSComUtils.PCSExc;
using System.Runtime.InteropServices;

namespace PCSComProduct.Costing.DS
{
	[Guid("C0A384B2-E56F-439e-B4FB-F983D51F0969")]
	public class ITM_CostCenterRateDS ////: IObjectDS
	{
		public ITM_CostCenterRateDS()
		{
		}

		private const string THIS = "PCSComProduct.Costing.DS.DS.ITM_CostCenterRateDS";


		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///        ITM_CostCenterRateVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				ITM_CostCenterRateVO objObject = (ITM_CostCenterRateVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);

				strSql = "INSERT INTO ITM_CostCenterRate("
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD + ")"
					+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUP_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUP_FLD].Value = objObject.LaborSetup;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD].Value = objObject.LaborSetupFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD].Value = objObject.LaborSetupVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUN_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUN_FLD].Value = objObject.LaborRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD].Value = objObject.LaborRunFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD].Value = objObject.LaborRunVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUP_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUP_FLD].Value = objObject.MachineSetup;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD].Value = objObject.MachineSetupFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD].Value = objObject.MachineSetupVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUN_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUN_FLD].Value = objObject.MachineRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD].Value = objObject.MachineRunFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD].Value = objObject.MachineRunVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD].Value = objObject.MaterialOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD].Value = objObject.EffectiveBeginDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD].Value = objObject.EffectiveEndDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.COSTCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.COSTCENTERID_FLD].Value = objObject.CostCenterID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();

			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql = "DELETE " + ITM_CostCenterRateTable.TABLE_NAME + " WHERE  " + "CostCenterRateID" + "=" + pintID.ToString();
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
				ocmdPCS = null;

			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}


			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       ITM_CostCenterRateVO
		///    </Outputs>
		///    <Returns>
		///       ITM_CostCenterRateVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public object GetObjectVO(int pintID, DateTime pdtmRollUpDate)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";

			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				strSql = "SELECT "
					+ ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD
					+ " FROM " + ITM_CostCenterRateTable.TABLE_NAME
					+ " WHERE " + ITM_CostCenterRateTable.COSTCENTERID_FLD + "=" + pintID
					+ " AND ? BETWEEN " + ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + " AND "
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + "";

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Parameters.Add(new OleDbParameter("RollUpDate", OleDbType.Date));
				ocmdPCS.Parameters["RollUpDate"].Value = pdtmRollUpDate;

				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				ITM_CostCenterRateVO objObject = new ITM_CostCenterRateVO();

				while (odrPCS.Read())
				{
					if (odrPCS[ITM_CostCenterRateTable.COSTCENTERRATEID_FLD] != DBNull.Value)
						objObject.CostCenterRateID = int.Parse(odrPCS[ITM_CostCenterRateTable.COSTCENTERRATEID_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORSETUP_FLD] != DBNull.Value)
						objObject.LaborSetup = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUP_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD] != DBNull.Value)
						objObject.LaborSetupFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD] != DBNull.Value)
						objObject.LaborSetupVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORRUN_FLD] != DBNull.Value)
						objObject.LaborRun = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUN_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD] != DBNull.Value)
						objObject.LaborRunFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD] != DBNull.Value)
						objObject.LaborRunVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINESETUP_FLD] != DBNull.Value)
						objObject.MachineSetup = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUP_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD] != DBNull.Value)
						objObject.MachineSetupFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD] != DBNull.Value)
						objObject.MachineSetupVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINERUN_FLD] != DBNull.Value)
						objObject.MachineRun = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUN_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD] != DBNull.Value)
						objObject.MachineRunFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD] != DBNull.Value)
						objObject.MachineRunVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD] != DBNull.Value)
						objObject.MaterialOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD] != DBNull.Value)
						objObject.EffectiveBeginDate = DateTime.Parse(odrPCS[ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD] != DBNull.Value)
						objObject.EffectiveEndDate = DateTime.Parse(odrPCS[ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD].ToString().Trim());
					if (odrPCS[ITM_CostCenterRateTable.COSTCENTERID_FLD] != DBNull.Value)
						objObject.CostCenterID = int.Parse(odrPCS[ITM_CostCenterRateTable.COSTCENTERID_FLD].ToString().Trim());

				}
				return objObject;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///       ITM_CostCenterRateVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			ITM_CostCenterRateVO objObject = (ITM_CostCenterRateVO) pobjObjecVO;


			//prepare value for parameters
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql = "UPDATE ITM_CostCenterRate SET "
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + "=   ?" + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD + "=  ?"
					+ " WHERE " + ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUP_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUP_FLD].Value = objObject.LaborSetup;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD].Value = objObject.LaborSetupFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD].Value = objObject.LaborSetupVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUN_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUN_FLD].Value = objObject.LaborRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD].Value = objObject.LaborRunFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD].Value = objObject.LaborRunVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUP_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUP_FLD].Value = objObject.MachineSetup;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD].Value = objObject.MachineSetupFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD].Value = objObject.MachineSetupVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUN_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUN_FLD].Value = objObject.MachineRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD].Value = objObject.MachineRunFixedOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD].Value = objObject.MachineRunVariableOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD].Value = objObject.MaterialOverhead;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD].Value = objObject.EffectiveBeginDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD].Value = objObject.EffectiveEndDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.COSTCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.COSTCENTERID_FLD].Value = objObject.CostCenterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(ITM_CostCenterRateTable.COSTCENTERRATEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[ITM_CostCenterRateTable.COSTCENTERRATEID_FLD].Value = objObject.CostCenterRateID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}

		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();


			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;

				strSql = "SELECT "
					+ ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD
					+ " FROM " + ITM_CostCenterRateTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();

				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, ITM_CostCenterRateTable.TABLE_NAME);

				return dstPCS;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from ITM_CostCenterRate by CCNID and CostCenterID
		///    </Description>
		///    <Inputs>
		///       int pintCCNID : CCNID        
		///       int pintCostCenterID : CostCenterRateID
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet ListByCCNAndCostCenter(int pintCCNID, int pintCostCenterID)
		{
			const string METHOD_NAME = THIS + ".ListByCCNAndCostCenter()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;

				strSql = "SELECT "
					+ ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.CCNID_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD
					+ " FROM " + ITM_CostCenterRateTable.TABLE_NAME
					+ " WHERE " + ITM_CostCenterRateTable.CCNID_FLD + " = " + pintCCNID.ToString()
					+ " and " + ITM_CostCenterRateTable.COSTCENTERID_FLD + " = " + pintCostCenterID.ToString();
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();

				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, ITM_CostCenterRateTable.TABLE_NAME);

				oconPCS = null;
				return dstPCS;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateDataSet(DataSet pData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS = null;
			OleDbCommandBuilder odcbPCS;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql = "SELECT "
					+ ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.CCNID_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD
					+ "  FROM " + ITM_CostCenterRateTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pData.EnforceConstraints = false;
				odadPCS.Update(pData, ITM_CostCenterRateTable.TABLE_NAME);

				oconPCS = null;
			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
				}

				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}
			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}

		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from ITM_CostCenterRate
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       ITM_CostCenterRateVO
		///    </Outputs>
		///    <Returns>
		///       ITM_CostCenterRateVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Wednesday, January 19, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();

			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				strSql = "SELECT "
					+ ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUP_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUN_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUP_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUN_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD + ","
					+ ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD + ","
					+ ITM_CostCenterRateTable.COSTCENTERID_FLD
					+ " FROM " + ITM_CostCenterRateTable.TABLE_NAME
					+ " WHERE " + ITM_CostCenterRateTable.COSTCENTERRATEID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				ITM_CostCenterRateVO objObject = new ITM_CostCenterRateVO();

				while (odrPCS.Read())
				{
					objObject.CostCenterRateID = int.Parse(odrPCS[ITM_CostCenterRateTable.COSTCENTERRATEID_FLD].ToString().Trim());
					objObject.LaborSetup = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUP_FLD].ToString().Trim());
					objObject.LaborSetupFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUPFIXEDOVERHEAD_FLD].ToString().Trim());
					objObject.LaborSetupVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORSETUPVARIABLEOVERHEAD_FLD].ToString().Trim());
					objObject.LaborRun = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUN_FLD].ToString().Trim());
					objObject.LaborRunFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUNFIXEDOVERHEAD_FLD].ToString().Trim());
					objObject.LaborRunVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.LABORRUNVARIABLEOVERHEAD_FLD].ToString().Trim());
					objObject.MachineSetup = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUP_FLD].ToString().Trim());
					objObject.MachineSetupFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUPFIXEDOVERHEAD_FLD].ToString().Trim());
					objObject.MachineSetupVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINESETUPVARIABLEOVERHEAD_FLD].ToString().Trim());
					objObject.MachineRun = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUN_FLD].ToString().Trim());
					objObject.MachineRunFixedOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUNFIXEDOVERHEAD_FLD].ToString().Trim());
					objObject.MachineRunVariableOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MACHINERUNVARIABLEOVERHEAD_FLD].ToString().Trim());
					objObject.MaterialOverhead = Decimal.Parse(odrPCS[ITM_CostCenterRateTable.MATERIALOVERHEAD_FLD].ToString().Trim());
					objObject.EffectiveBeginDate = DateTime.Parse(odrPCS[ITM_CostCenterRateTable.EFFECTIVEBEGINDATE_FLD].ToString().Trim());
					objObject.EffectiveEndDate = DateTime.Parse(odrPCS[ITM_CostCenterRateTable.EFFECTIVEENDDATE_FLD].ToString().Trim());
					objObject.CostCenterID = int.Parse(odrPCS[ITM_CostCenterRateTable.COSTCENTERID_FLD].ToString().Trim());

				}
				return objObject;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}

	}
}